package net.esj.basic.utils;

import org.hibernate.id.IdentifierGenerationException;

public final class TreeIDCreator {

	public static final Long createFirstChild(Long parentId) throws IdentifierGenerationException{
		Long chd = (parentId<<8) ;
		if(chd<0){
			throw new IdentifierGenerationException("ID over maxlength");
		}
		return chd+1;
	}
	
	public static final Long createNext(Long brotherId){
		return new Long(brotherId+1);
	}
	
	public static final Long getParent(Long childId){
		return getParent(childId,1);
	}
	
	public static final Long getParent(Long childId,int lvl){
		Long parent = childId;
		for(int i=0;i<lvl ;i++){
			parent = parent >>8;
		}
		return parent;
	}
	
	
}
